package com.mh.controller;

import com.mh.common.R;
import com.mh.pojo.AppointmentInfo;
import com.mh.pojo.AppointmentType;
import com.mh.pojo.DoctorInfo;
import com.mh.service.AppointmentInfoService;
import com.mh.service.AppointmentTypeService;
import com.mh.service.DoctorInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Date:2023/4/13
 * author:zmh
 * description:学生界面相关接口
 **/

@RestController
@Slf4j
@RequestMapping("/studentPages")
@CrossOrigin
public class StudentPageController {

    @Autowired
    private AppointmentInfoService appointmentInfoService;

    @Autowired
    private DoctorInfoService doctorInfoService;

    @Autowired
    private AppointmentTypeService appointmentTypeService;

    /**
     * 添加预约信息
     * @param appointmentInfo 接收数据
     */
    @PostMapping
    public R<String> getAppointmentInfo(@RequestBody AppointmentInfo appointmentInfo){
        // 调用service中业务方法，填充默认字段
        String info = appointmentInfoService.addAppointmentInfo(appointmentInfo);
        return R.success(info);
    }

    /**
     * 获取所有信息-只显示姓名，预约时间，预约状态
     * @return 返回预约信息列表
     */
    @GetMapping
    public R<List<AppointmentInfo>> getAllAppointmentInfo(){
        List<AppointmentInfo> list = appointmentInfoService.getALlByStudentPage();
        return R.success(list);
    }

    /**
     * 根据传入名称查找出此此学生的预约信息
     * @param studentName 学生姓名
     * @return 返回单个学生的预约信息
     */
    @GetMapping("/getOnes")
    public R<List<AppointmentInfo>> getOneAppointmentInfo(String studentName){
        List<AppointmentInfo> currentUserList = appointmentInfoService.getOneStudentAppointmentInfo(studentName);
        return R.success(currentUserList);
    }

    /**
     * 获取在线的医生信息列表
     */
    @GetMapping("/getOnlineDoctor")
    public R<List<DoctorInfo>> getOnlineDoctor(){
        List<DoctorInfo> onlineDoctors = doctorInfoService.getOnlineDoctor();
        return R.success(onlineDoctors);
    }

    /**
     * 获取所有看病类型
     * @return 看病类型列表
     */
    @GetMapping("/getTypes")
    public R<List<String>> getAllType(){
        List<AppointmentType> list = appointmentTypeService.list();
        // 将类型字段抽取出来
        List<String> types = list.stream().map(item->{
            return item.getType();
        }).collect(Collectors.toList());
        return R.success(types);
    }

    /**
     * 修改预约信息的操作医生字段
     * @param uid 预约单号
     * @param doctorName 医生姓名
     * @return 执行状态结果
     */
    @PutMapping("/modifyType")
    public R<String> modifyAppointmentOperationDoctor(String uid, String doctorName){
        String info = appointmentInfoService.modifyAppointmentOperationDoctor(uid, doctorName);
        return R.success(info);
    }
}
